## Python Script "forum_view_query"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=
##title=Query the items for the view, according to few parameters
##

from Products.CMFPlone import Batch

search = context.REQUEST.get('SearchableText', None)
review = context.REQUEST.get('review', None)

results = search and context.getAllContents(search_term=search)

if not results:
    results = review and context.getReviewableContents(limit=None)

if not results:
    results = context.getDirectContents()

# batches 'results'
b_size  = context.getBatchSize() or 15;
b_start = context.REQUEST.get('b_start', 0);
batch   = Batch(results, b_size, int(b_start), orphan=1)

return {
    'size'      : len(results),
    'b_size'    : b_size,
    'is_batched': len(results) > b_size,
    'batch'     : batch,
    }
